package impl

import (
	"gitee.com/fzh-show/mcenter/apps/user"
	"gitee.com/fzh-show/mcenter/conf"
	"go.mongodb.org/mongo-driver/mongo"
	"google.golang.org/grpc"

	"github.com/infraboard/mcube/ioc"
)

var _ user.Service = (*impl)(nil)

func init() {
	ioc.RegistryController(&impl{})
}

type impl struct {
	user.UnimplementedRpcServer
	ioc.IocObjectImpl
	// 依赖数据的集合(collection)就是表
	col *mongo.Collection
}

func (i *impl) Init() error {
	// 补充依赖
	db, err := conf.C().Mongo.GetDB()
	if err != nil {
		panic(err)
	}
	// db.Collection(token.AppName)
	i.col = db.Collection("users")
	return nil
}

func (i *impl) Name() string {
	return user.AppName
}

func (i *impl) Registry(server *grpc.Server) {
	user.RegisterRpcServer(server, i)
}
